package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import swimv2.ejb.util.LoginToken;
import util.HtmlUtil;

/**
 * Servlet implementation class HomeUtente
 */
public class HomeUtente extends Servlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public HomeUtente() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		request.setAttribute("titolo", "Home Utente");

		LoginToken tok = (LoginToken) request.getSession().getAttribute("LoginToken");
		if (tok == null || tok.isVisitatore()) {
			HtmlUtil.redirect(request, response, "/");
			return;
		}
			HtmlUtil.inviaHeader(request, response);

			String azione = (String) request.getParameter("azione");
			HtmlUtil.inviaIntestazioneUtente(request, response);
			if (azione != null && azione.equals("home")) {
				HtmlUtil.includi(request, response,"/WEB-INF/pages/homeUtente.jsp?from=home");
				HtmlUtil.inviaFooter(request, response);
			} else if (azione != null && azione.equals("logOk")) {
				HtmlUtil.includi(request, response,"/WEB-INF/pages/homeUtente.jsp?from=login");

			}
			else
			{
				
			}
			HtmlUtil.inviaFooter(request, response);

		

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	

}
